<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="org.apache.shiro.web.filter.authc.FormAuthenticationFilter"%>
<%@ page import="org.apache.shiro.authc.ExcessiveAttemptsException"%>
<%@ page import="org.apache.shiro.authc.IncorrectCredentialsException"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
	<title>欢迎您登录</title>
<script>
$(document).ready(function() {
	mz_datatbles.dt();
});

var oTable;
var type=${type};
var url="";
if(type=='1'){
	url="${ctx}/user/auth/list";
}else if(type=='2'){
	url="${ctx}/user/auth/menuList";
}else{
	url="${ctx}/user/auth/list";
}
mz_datatbles = {
	dt:function(){
		if($('#listTable').length) {
			oTable = $("#listTable").dataTable({
	    		"fnServerParams": function ( aoData ) {
	    			jQuery.each( $("form#listForm").serializeArray(), function(i, field){
	    				aoData.push( field );    
					});
	    		} ,    
				"bScrollCollapse": false,
	        	"bServerSide": true,
	        	"bProcessing": true,
	        	"bSort" : true, 
	        	"sPaginationType": "bootstrap",
	        	"sDom": "<r>t<'row'<'span6'li><'span6'p>>",
	        	"sAjaxSource": url,
	        	"oLanguage": {  
	        		"sProcessing": "数据加载中",
	        		"sLoadingRecords": "Please wait - loading...",
	        		"sLengthMenu": "每页显示 _MENU_ 行&nbsp;",
	        		"sSearch": "_INPUT_",
	        		"oPaginate": {       "sFirst": "首页" ,  "sPrevious": "前页" ,"sNext": "下页", "sLast": "尾页"     },
	        		"sZeroRecords": "未找到符合条件的数据",
	        		"sEmptyTable": "未找到符合条件的数据"
	        	} ,
	       	 	"aoColumns": [
					{ "mDataProp": "authCode", "sName": "authCode", "sClass": "center" },
					{ "mDataProp": "authName", "sName": "authName", "sClass": "center" },
					{ "mDataProp": "authTypeName", "sName": "authTypeName", "sClass": "center" },
					{ "mDataProp": "authParentCode", "sName": "authParentCode", "sClass": "center" },
					{ "mDataProp": "menuAddr", "sName": "menuAddr", "sClass": "center" },
					{ "bSortable": false, "mDataProp": null, "sClass": "center",
						"fnRender" : function(oObj) {
							var html ="";
							var authType=oObj.aData.authType;
							if(authType=='A'){
								html+='<a title="查看子菜单" class="sepV_a"  href="${ctx}/user/auth/list/'+oObj.aData.authCode+'">查看子菜单</a>';
								
								html+=
								'<a title="新建子菜单" class="sepV_a"  href="${ctx}/user/auth/create/'+oObj.aData.authCode+'">新建子菜单</a> ';
							}
								html+=
								'<a title="修改" class="sepV_a" href="${ctx}/user/auth/update/'+oObj.aData.authId+'">' +
								'<i class="icon-pencil"></i></a>'+
								'<a title="删除" class="sepV_a" onclick="return delConfirm()" href="${ctx}/user/auth/delete/'+oObj.aData.authId+'">' +
								'<i class="icon-trash"></i></a>';
								if(authType=='A'){
									html+=
									'<a title="上移" class="sepV_a" href="${ctx}/user/auth/moveUp/'+oObj.aData.authId+'">' +
									'<i class="icon-arrow-up"></i></a>'+
									'<a title="下移" class="sepV_a" href="${ctx}/user/auth/moveDown/'+oObj.aData.authId+'">' +
									'<i class="icon-arrow-down"></i></a>';
								}
							return html; 
						}
					}
				] ,
				"fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
	        		getFrameHeight();
	        		return "&nbsp;"+(iTotal>0?iStart:0)+" ~ "+iEnd+" 行 总共"+iTotal+"行 ";  
	        	} 
	    	});
		}
	}
};
var message = '${message}';
if(message!=null && message!=""){
	alert(message);
}

function delConfirm(){
	if(confirm("权限资源不要胡乱删除，是否真的确认删除?")){
		return true;
	}else{
		return false;
	}
}

function toSave(){
	var authCode= $("#authCode").val();
	window.location.href = "${ctx}/user/auth/create/"+authCode;
}
function back(){
	window.history.back();
}
</script>
</head>

<body>
        	<div>
            	<div id="jCrumbs" class="breadCrumb module">
				    <ul>
				        <li>
				            <a href="#"><i class="icon-home" style="margin-top: 2px;"></i></a>
				        </li>
				        <li>
				            	权限管理
				        </li>
				        <li>
				            	权限列表
				        </li>
				         <c:if test="${authName!='' }">
					        <li>
					            	${authName}
					        </li>
					         <div class="btn-group pull-right"> <a href="javascript:window.history.back();"><b>返回</b></a></div>
				        </c:if>
				    </ul>
				</div>
				<div class="row-fluid">
		    		<div class="span12">
		        		<div class="row-fluid">
							<div class="span12">
								<form name="listForm" id="listForm">
								<input type="hidden" id="authCode" name="authCode" value="${authCode}"/>
									<table class="table table-bordered table-striped table_vam dataTable">
										<tbody>
											<tr>
												<th>权限名称</th>
												<td>
													<input type="text" name="authName" />
												 </td>
											</tr>
											<tr>
												<td colspan="4">								
													<div class="row">
														<div class="span4">
															<div class="dt_actions"><div class="btn-group"></div></div>
														</div>
														<div class="span4 center">
															<button class="btn  btn_search" type="button" onclick="oTable.fnDraw();">查询</button>&nbsp;&nbsp;&nbsp;&nbsp;
															<button class="btn" type="reset">重置</button>
														</div>
														<div class="span4">
															<div class="btn-group pull-right">
																<button class="btn" style="background-color: #D7E6FA" type="button" onclick="toSave()">新增权限</button>
															</div>
														</div>
													</div>
												</td>
											</tr>
										</tbody>
									</table>
								</form>
							</div>
						</div>
					<table id="listTable" class="table table-bordered table-striped table_vam dataTable">
		            	<thead>
		                	<tr>
								<th width="15%">权限编码</th>
								<th width="15%">权限名称</th>
								<th width="10%">权限类型</th>
								<th width="13%">权限父编码</th>
								<th width="15%">菜单地址</th>
								<th width="32%" class="center sorting">操作</th>
							</tr>
		            	</thead>
		            	<tbody>
		                	<tr>
		                    	<td class="dataTables_empty" colspan="6"></td>
		                	</tr>
		            	</tbody>
		        	</table>
		        </div>
		    </div>
		</div>
</body>
</html>
